from sqlalchemy import Column, ForeignKey, Integer
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import backref, relation
from divirt import sqlalchemy_meta_data
from divirt import logging
from nic import Nic
from switch import Switch

log = logging.getLogger('divirt.components.switchconn')

Base = declarative_base(metadata=sqlalchemy_meta_data)
class SwitchConn(Base):
    # Table
    __tablename__ = 'switchconns'
    id = Column(Integer, primary_key=True)
    nic_id = Column(Integer, ForeignKey('nics.id'))
    switch_id = Column(Integer, ForeignKey('switches.id'))

    # Relations
    nic = relation(Nic, backref=backref('switchconn'))
    switch = relation(Switch, backref=backref('switchconn'))

    def __init__(self, nic_id=None, switch_id=None):
        self.nic_id = nic_id
        self.switch_id = switch_id


    def __repr__(self):
        return '<SwitchConn(id=%s, nic_id=%s, switch_id=%s)>' \
            % (self.id, self.nic_id, self.switch_id)
